#include "stdafx.h"



void createList (LinkedListPointer StartOfList)
{
	//StartOfList=(LinkedListPointer)malloc(sizeof(LinkedListNode));
	StartOfList->next=NULL;
}

void addToList (char* WordToAdd, LinkedListPointer StartOfList)
{
	LinkedListPointer NodeToAdd;
	NodeToAdd=(LinkedListPointer)malloc(sizeof(LinkedListNode));
	strcpy(NodeToAdd->bindedword,WordToAdd);
	NodeToAdd->next=StartOfList->next;
	StartOfList->next=NodeToAdd;
}

void delFromList (LinkedListPointer StartOfList)
{
	LinkedListNode temp;
	temp.next=StartOfList->next;
	StartOfList->next=StartOfList->next->next;
	free(temp.next);
}

int listIsEmpty (LinkedListPointer StartOfList)
{
	if (StartOfList->next==NULL)
		return 1;
return 0;
}

int searchListForExistence (LinkedListPointer StartOfList, char *binded)
{
	LinkedListPointer RunningNode;
	if (listIsEmpty(StartOfList))
		return 0;
	if (binded==NULL)
		return 0;
	RunningNode=(LinkedListPointer)malloc(sizeof(LinkedListNode));
	RunningNode->next=StartOfList->next;
	strcpy(RunningNode->bindedword,StartOfList->next->bindedword);
	while (RunningNode->next!=NULL)
	{
		if (strcmp(binded,RunningNode->bindedword)==0)
		{
			free(RunningNode);
			return 1;
		}
		else
		{
			strcpy(RunningNode->bindedword,RunningNode->next->bindedword);
			RunningNode->next=RunningNode->next->next;
			if (RunningNode->next==NULL)
			{
				if (strcmp(binded,RunningNode->bindedword)==0)
				{
					free(RunningNode);
					return 1;
				}
			}
		}
	}
	free(RunningNode);
	return 0;
}

void deleteList(LinkedListPointer StartOfList)
{
	free(StartOfList);
}

void printList (const LinkedListPointer StartOfList)
{
	LinkedListPointer temp;
	temp=(LinkedListPointer)malloc(sizeof(LinkedListNode));
	temp=StartOfList->next;
	while(temp->next!=NULL)
	{
		puts(temp->bindedword);
		temp=temp->next;
		if (temp->next==NULL)
			puts(temp->bindedword);
	}
	free(temp);
}


		
